package com.wzdigit.wms.wms.service.core.transfer;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.wms.basic.domain.transfer.TransferDtlGoods;
import com.wzdigit.wms.basic.mapper.core.transfer.TransferDtlGoodsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * <p>
 * 调拨单单货品清单 服务类
 * </p>
 *
 * @author
 * @since 2021-01-19
 */
@Service
@Slf4j
public class TransferDtlGoodsService {

    @Autowired
    TransferDtlGoodsMapper transferDtlGoodsMapper;

    /**
     * 根据入参实体新增记录
     *
     * @param transferDtlGoods
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public TransferDtlGoods addNewOne(TransferDtlGoods transferDtlGoods) {
        int row = transferDtlGoodsMapper.insert(transferDtlGoods);
        log.info("成功新增{}条记录", row);

        return transferDtlGoods;
    }

    /**
     * 根据入参实体
     *
     * @param transferDtlGoods
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public TransferDtlGoods updateOne(TransferDtlGoods transferDtlGoods) {
        int row = transferDtlGoodsMapper.updateById(transferDtlGoods);
        log.info("成功更新{}条记录", row);
        return transferDtlGoods;
    }

    /**
     * 根据入参集合实体新增记录
     *
     * @param transferDtlGoods
     */
    public List<TransferDtlGoods> addNewList(List<TransferDtlGoods> transferDtlGoods) {
        for (TransferDtlGoods transferDtlGood : transferDtlGoods) {
            addNewOne(transferDtlGood);
        }

        return transferDtlGoods;
    }

    /**
     * 根据明细ID查询清单集合
     * @param transferDtlId
     * @return
     */
    public List<TransferDtlGoods> selectByDtlId(Long transferDtlId) {
        //创建类型的条件构造器
        QueryWrapper<TransferDtlGoods> wrapper = new QueryWrapper<>();
        wrapper.eq("TRANSFER_DTL_ID", transferDtlId);
        List<TransferDtlGoods> transferDtlGoodsList = transferDtlGoodsMapper.selectList(wrapper);
        return transferDtlGoodsList;
    }

}
